package model;


import com.google.gson.annotations.Expose;

import java.util.Objects;

public class User {
    @Expose
    private String userName;

    @Expose
    private int age;

    private String password; // 默认不标注 @Expose，则不会被序列化

    public User(String userName, int age, String password) {
        this.userName = userName;
        this.age = age;
        this.password = password;
    }

    // Getters and Setters
    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    @Override
    public String toString() {
        return "User{" +
                "userName='" + userName + '\'' +
                ", age=" + age +
                ", password='" + password + '\'' +
                '}';
    }

    // 重写 equals 方法
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        User user = (User) o;
        return age == user.age &&
                Objects.equals(userName, user.userName) &&
                Objects.equals(password, user.password);
    }

    // 重写 hashCode 方法
    @Override
    public int hashCode() {
        return Objects.hash(userName, age, password);
    }
}
